package com.neuedu.corejava.ch13.homework;

public class ThreadFind implements Runnable {

	private int b;
	private int e;
	
	public ThreadFind(int b, int e) {
		super();
		this.b = b;
		this.e = e;
	}

	@Override
	public void run() {
		boolean flag;
		for(int i=b;i<=e;i++) {
			flag=true;
			for(int j=2;j<i;j++) {
				if(i%j==0) {
					flag=false;
					break;
				}
			}
			if(flag==true) {
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e1) {
					e1.printStackTrace();
				}
				System.out.println(i);
			}
		}
	}
	public static void main(String[] args) {

		ThreadFind find=new ThreadFind(1, 1000);
		ThreadFind find2=new ThreadFind(1001, 2000);
		ThreadFind find3=new ThreadFind(2001, 3000);
		Thread thread=new Thread(find);
		Thread thread2=new Thread(find2);
		Thread thread3=new Thread(find3);
		
		thread.start();
		thread2.start();
		thread3.start();
	}
}
